package com.shujia.flink

import org.apache.flink.api.scala._
import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment

object StreamWordCOunt {
  def main(args: Array[String]): Unit = {


    //创建flink运行环境
    val env = StreamExecutionEnvironment.getExecutionEnvironment

    //读取socket创建DataStream  nc -lk 9999
    val ds = env.socketTextStream("node1", 8888)

    val countDS = ds
      .flatMap(_.split(","))
      .map((_, 1))
      //reduceByKey
      .keyBy(0) //指定列索引
      .sum(1)

    countDS.print()

    //启动实时 处理程序
    env.execute("StreamWordCOunt")


  }
}
